//
//  AMTabBarViewController.m
//  AMwb
//
//  Created by zhc on 15/11/28.
//  Copyright © 2015年 zhc. All rights reserved.
//

#import "AMTabBarViewController.h"
#import "AMhomeTableViewController.h"
#import "AMmessageTableViewController.h"
#import "AMdiscoverTableViewController.h"
#import "AMprofileTableViewController.h"
#import "AMNavigationViewController.h"
#import "AMTabBar.h"


#define HWRandomColor HMColor(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))

#define HMColor(r,g,b)  [UIColor colorWithRed:(r)/255.0 green: (g)/255.0 blue:  (b)/255.0 alpha:1.0]



@interface AMTabBarViewController ()<AMTabBarDelegate>

@end

@implementation AMTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //设置底部4个按钮
    AMhomeTableViewController *message=[[AMhomeTableViewController alloc]init];
    [self addChildVc:message  WithTile:@"主页" andImage:@"tabbar_home" selectedImage:@"tabbar_home_selected"];
    
    AMmessageTableViewController *discover=[[AMmessageTableViewController alloc]init];
    [self addChildVc:discover WithTile:@"信息" andImage:@"tabbar_message_center" selectedImage:@"tabbar_message_center_selected"];
    
   // [self addChildViewController:[[UIViewController alloc]init]];
    
    AMdiscoverTableViewController *profile=[[AMdiscoverTableViewController alloc]init];
    [self addChildVc:profile  WithTile:@"发现" andImage:@"tabbar_discover" selectedImage:@"tabbar_discover_selected"];
    
    AMprofileTableViewController *home=[[AMprofileTableViewController alloc]init];
    [self addChildVc:home WithTile:@"我" andImage:@"tabbar_profile" selectedImage:@"tabbar_profile_selected"];
    
    
    //[tabbarVc addChildViewController:vc4];
    // tabbarVc.viewControllers=@[home,message,discover,profile];
    
    //self.tabBar = [[AMTabBar alloc]init];
    
    //设置中间的按钮
    [self setValue:[[AMTabBar alloc]init] forKey:@"tabBar"];
    
    
    
    
    //设置tabBar的代理
    
    
    AMTabBar *tabBar=[[AMTabBar alloc]init];
    
    tabBar.delegate = self;
    
    

    
    
   
    
}

//封装tabBar的创建

- (void)addChildVc:(UIViewController *)Vc   WithTile:(NSString *)titile andImage:(NSString *)image selectedImage:(NSString *)selecetImage{
    
    //UIViewController *childCv=[[UIViewController alloc]init];
    //设置内容
    Vc.tabBarItem.title=titile;
   // Vc.title=titile;
    
    Vc.tabBarItem.image=[UIImage imageNamed:image];
    Vc.tabBarItem.selectedImage=[[UIImage imageNamed:selecetImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   

    
    //Vc.view.backgroundColor = HWRandomColor;
     //设置内容属性
    NSMutableDictionary *textAttrs =[NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HMColor(200, 160, 13);
    
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    
    [Vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [Vc.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    
    AMNavigationViewController *nav=[[AMNavigationViewController alloc] initWithRootViewController:Vc];
    
    [self addChildViewController:nav];
    
    

    
    //return childCv;
    
}

#pragma mark-AMTabBar代理方法
//点击加号modal
//:(AMTabBar *)tabBar
- (void)AMTabBarDidClickPlusButton:(AMTabBar *)tabBar{
    
    UIViewController *vc=[[UIViewController alloc]init];
    vc.view.backgroundColor=[UIColor redColor];
    [self presentViewController:vc animated:YES completion:nil];
    
    

    //   [self presentViewController:vc animated:YES completion:nil];
    
   
    
}




@end
